import PROVINCE from './province.js'

export const formConf = {
  formRef: 'elForm',
  size: 'small',
  labelPosition: 'right',
  labelWidth: 100,
  gutter: 15,
  disabled: false,
  span: 24,
  formBtns: true
}
export const bpmComponents=[
  {
    label: '组织机构',
    showLabel: true,
    tag: 'ai-ou-select',
    tagIcon: 'dept',
    defaultValue: null,
    tabList: ['org'],
    buttonType: 'button',
    title: '组织机构',
    searchable: true,
    maxNum: 1,
    tagConfig: {
      type: 'info',
      closable: true,
      'disable-transitions': false,
      hit: false,
      color: undefined,
      size: 'small',
      effect: 'light'
    },
    style: { width: '100%' },
    span: 24,
    labelWidth: null,
    disabled: false,
    required: true,
    regList: [],
    changeTag: true,
    proCondition: true,
    asSummary: false
  },
  {
    label: '金额',
    showLabel: true,
    tag: 'fc-amount',
    tagIcon: 'amount',
    placeholder: '请输入',
    defaultValue: undefined,
    style: { width: null },
    span: 24,
    labelWidth: null,
    min: undefined,
    max: undefined,
    step: undefined,
    'step-strictly': false,
    precision: undefined,
    'controls-position': 'right',
    disabled: false,
    required: false,
    regList: [],
    changeTag: true,
    proCondition: true,
    showChinese: true
  },{ 
      label: '编辑器',
      showLabel: true,
      changeTag: true,
      labelWidth: null,
      showLabel: true,
    tag: 'tinymce',
      tagIcon: 'rich-text',
      defaultValue: null,
      span: 24,
      layout: 'colFormItem',
      required: true,
      regList: [],
      document: 'http://tinymce.ax-z.cn',
     
    placeholder: '请输入',
    height: 300, // 编辑器高度
    branding: false // 隐藏右下角品牌烙印
  },
  
  {
    label: '省市区',
    showLabel: true,
    tag: 'el-cascader',
    tagIcon: 'area',
    placeholder: '请选择',
    defaultValue: [],
    span: 24,
    labelWidth: null,
    style: { width: '100%' },
    props: {
        
      props: {
        multiple: false,
      }
    },
    'show-all-levels': true,
    disabled: false,
    clearable: true,
    filterable: false,
    required: false,
    options: PROVINCE,
    dataType: 'static',
    labelKey: 'label',
    valueKey: 'value',
    childrenKey: 'children',
    separator: '/',
    regList: [],
    changeTag: true,
    proCondition: false,
    asSummary: false
  },
  {
    label: '计算公式',
    type: 'calculate',
    showLabel: true,
    tag: 'fc-calculate',
    showChinese: true,
    tagIcon: 'calculate',
    defaultValue: null,
    labelWidth: null,
    disabled: false,
    required: false,
    changeTag: true,
    expression: [],
    proCondition: true,
    asSummary: false
  },
]
export const inputComponents = [{
  label: '单行输入框',
  showLabel: true,
  tag: 'el-input',
  tagIcon: 'input',
  placeholder: '请输入',
  defaultValue: undefined,
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  clearable: true,
  prepend: '',
  append: '',
  'prefix-icon': '',
  'suffix-icon': '',
  maxlength: null,
  'show-word-limit': false,
  readonly: false,
  disabled: false,
  required: false,
  regList: [],
  __slot__:{},
  changeTag: true,
  proCondition: false,
  asSummary: false
},
{
  label: '多行输入框',
  showLabel: true,
  tag: 'el-input',
  tagIcon: 'textarea',
  type: 'textarea',
  placeholder: '请输入',
  defaultValue: undefined,
  span: 24,
  labelWidth: null,
  autosize: {
    minRows: 4,
    maxRows: 4
  },
  style: { width: '100%' },
  maxlength: null,
  'show-word-limit': false,
  readonly: false,
  disabled: false,
  required: false,
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
  {
    label: '密码',
    showLabel: true,
  tag: 'el-input',
    tagIcon: 'password',
    placeholder: '请输入',
    defaultValue: undefined,
    span: 24,
    'show-password': true,
    labelWidth: null,
    style: { width: '100%' },
    clearable: true,
    prepend: '',
    append: '',
    'prefix-icon': '',
    'suffix-icon': '',
    maxlength: null,
    'show-word-limit': false,
    readonly: false,
    disabled: false,
    required: false,
    regList: [],
    changeTag: true,
proCondition: false,
asSummary: false
  },
{
  label: '数字输入框',
  showLabel: true,
  tag: 'el-input-number',
  tagIcon: 'number',
  placeholder: '',
  defaultValue: undefined,
  style: { width: null },
  span: 24,
  labelWidth: null,
  min: undefined,
  max: undefined,
  step: undefined,
  'step-strictly': false,
  precision: undefined,
  'controls-position': 'right',
  disabled: false,
  required: false,
  regList: [],
  changeTag: true,
  proCondition: true
},
]

export const selectComponents = [{
  label: '下拉选择',
  showLabel: true,
  tag: 'el-select-wrap',
  tagIcon: 'select',
  placeholder: '请选择',
  style: { width: '100%' },
  defaultValue: undefined,
  span: 24,
  labelWidth: null,
  clearable: true,
  disabled: false,
  required: false,
  filterable: false,
  multiple: false,

  
  options: [{
    label: '选项一',
    value: '选项一'
  }, {
    label: '选项二',
    value: '选项二'
  }],
  regList: [],
  changeTag: true,
  proCondition: true
},
{
  label: '级联选择',
  showLabel: true,
  tag: 'el-cascader',
  tagIcon: 'cascader',
  placeholder: '请选择',
  defaultValue: [],
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  props: {
    props: {
      multiple: false
    }
  },
  'show-all-levels': true,
  disabled: false,
  clearable: true,
  filterable: false,
  required: false,
 
  options: [{
    id: 1,
    value: '选项1',
    label: '选项1',
    children: [{
      id: 2,
      value: '选项1-1',
      label: '选项1-1'
    }]
  }],
  dataType: 'static',
  labelKey: 'label',
  valueKey: 'value',
  childrenKey: 'children',
  separator: '/',
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
{
  label: '单选框组',
  showLabel: true,
  tag: 'el-radio-group-wrap',
  tagIcon: 'radio',
  defaultValue: undefined,
  span: 24,
  labelWidth: null,
  style: {},
  optionType: 'default',
  border: false,
  size: 'medium',
  disabled: false,
  required: false,
  options: [{
    label: '选项一',
    value: '选项一'
  }, {
    label: '选项二',
    value: '选项二'
  }],
  regList: [],
  changeTag: true,
  proCondition: true
},
{
  label: '多选框组',
  showLabel: true,
  tag: 'el-checkbox-group-wrap',
  tagIcon: 'checkbox',
  defaultValue: [],
  span: 24,
  labelWidth: null,
  style: {},
  optionType: 'default',
  border: false,
  size: 'medium',
  disabled: false,
  required: false,
  options: [{
    label: '选项一',
    value: '选项一'
  }, {
    label: '选项二',
    value: '选项二'
  }],
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
  {
    label: '开关',
    showLabel: true,
  tag: 'el-switch',
    tagIcon: 'switch',
    defaultValue: false,
    span: 24,
    labelWidth: null,
    style: {},
    disabled: false,
    required: false,
    'active-text': '',
    'inactive-text': '',
    'active-color': null,
    'inactive-color': null,
    'active-value': true,
    'inactive-value': false,
    regList: [],
    changeTag: true,
proCondition: false,
asSummary: false
  },
{
  label: '滑块',
  showLabel: true,
  tag: 'el-slider',
  tagIcon: 'slider',
  defaultValue: null,
  span: 24,
  labelWidth: null,
  disabled: false,
  required: false,
  min: 0,
  max: 100,
  step: 1,
  'show-stops': false,
  range: false,
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},


{
  // el-time-picker
  label: '时间选择',
  showLabel: true,
  tag: 'el-time-picker',
  tagIcon: 'time',
  placeholder: '请选择',
  defaultValue: null,
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  disabled: false,
  clearable: true,
  required: false,
  'picker-options': {
    selectableRange: '00:00:00-23:59:59'
  },
  format: 'HH:mm:ss',
  'value-format': 'HH:mm:ss',
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
{
  label: '时间范围',
  showLabel: true,
  tag: 'fc-time-duration',
  showDuration: false,
  tagIcon: 'time-range',
  defaultValue: null,
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  disabled: false,
  clearable: true,
  required: false,
  'is-range': true,
  'range-separator': '至',
  'start-placeholder': '开始时间',
  'end-placeholder': '结束时间',
  format: 'HH:mm:ss',
  'value-format': 'HH:mm:ss',
  regList: [],
  changeTag: true,
  proCondition: true,
  asSummary: false
},
{
  label: '日期选择',
  showLabel: true,
  tag: 'el-date-picker',
  tagIcon: 'date',
  placeholder: '请选择',
  defaultValue: null,
  type: 'date',
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  disabled: false,
  clearable: true,
  required: false,
  format: 'YYYY-MM-DD',
  'value-format': 'YYYY-MM-DD',
  readonly: false,
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
{
  label: '日期范围',
  showLabel: true,
  tag: 'fc-date-duration',
  showDuration: false,
  tagIcon: 'date-range',
  defaultValue: null,
  span: 24,
  labelWidth: null,
  style: { width: '100%' },
  type: 'daterange',
  'range-separator': '至',
  'start-placeholder': '开始日期',
  'end-placeholder': '结束日期',
  disabled: false,
  clearable: true,
  required: false,
  format: 'YYYY-MM-DD',
  'value-format': 'YYYY-MM-DD',
  readonly: false,
  regList: [],
  changeTag: true,
  proCondition: true,
  asSummary: false
},
{
  label: '评分',
  showLabel: true,
  tag: 'el-rate',
  tagIcon: 'rate',
  defaultValue: 0,
  span: 24,
  labelWidth: null,
  style: {},
  max: 5,
  'allow-half': false,
  'show-text': false,
  'show-score': false,
  disabled: false,
  required: false,
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},
  {
    label: '颜色选择',
    showLabel: true,
  tag: 'el-color-picker',
    tagIcon: 'color',
    defaultValue: null,
    labelWidth: null,
    'show-alpha': false,
    'color-format': '',
    disabled: false,
    required: false,
    size: 'medium',
    regList: [],
    changeTag: true,
proCondition: false,
asSummary: false
  },
{
  label: '附件',
  showLabel: true,
  tag: 'el-upload-wrap',
  tagIcon: 'upload',
  action: 'https://localhost/upload/',
  defaultValue: [],
  labelWidth: null,
  disabled: false,
  required: false,
  accept: '',
  name: 'file',
  'auto-upload': true,
  showTip: false,
  buttonText: '点击上传附件',
  fileSize: 20,
  sizeUnit: 'MB',
  'list-type': 'text',
  multiple: false,
  regList: [],
  changeTag: true,
  proCondition: false,
  asSummary: false
},

]
// 容器组件
export const layoutComponents = [{
  layout: 'rowFormItem',
  tag:'el-row',
  cols:[{span:12,children:[]},{span:12,children:[]}],
  rowType: 'layout',
  tagIcon: 'row',
  type: 'default',
  justify: 'start',
  align: 'top',
  label: '行容器',
  layoutTree: true,
  children: [],
  showDivider: true,
  description:'为提供足够灵活性，没有限制行容器子项必须为列容器'
},

{
  layout: 'rowFormItem',
  tag:'el-col',
  span:8,
  offset:0,
  cols:[{span:12,children:[]},{span:12,children:[]}],
  rowType: 'layout',
  tagIcon: 'col',
  type: 'default',
  justify: 'start',
  label: '列容器', 
  children: [], 
  description:'为提供足够灵活性，没有限制列必须在行容器内'
},
{
  showLabel: false,
  tag: 'el-tabs',
  span: 24,
  tabPosition:'top',
  disabled: false,
  tagIcon: 'tab',
  children:[],//{tag:'el-tab-pane',rowType:'table', label:'Tab1',value:'Tab1',children:[]}],
  tabpanes:[{  label:'Tab1',value:'Tab1' ,content:'tab1',children:[]},{  label:'Tab2',value:'Tab2' ,content:'tab2',children:[]}],
  activeName:'Tab1',
  type: 'border-card',
  justify: 'start',
  align: 'top',
  label: '标签页',
  layoutTree: false, 
  actionText: '添加',
  showDivider: true,
  defaultValue:'Tab1'
}, 
{
  layout: 'rowFormItem',
  tag:'el-table',
  rowType: 'table',
  tagIcon: 'table',
  showLabel: true,
  //tag: 'fc-input-table',
  type: 'table', // list
  justify: 'start',
  align: 'top',
  label: '表格/明细',
  layoutTree: false,
  children: [],
  actionText: '添加',
  tableConf: {},
  'show-summary': true,
  defaultValue: []
},
{
  label: '按钮',
      showLabel: true,
      changeTag: true,
      labelWidth: null,
      showLabel: true,
  tag: 'el-button',
      tagIcon: 'button',
      defaultValue: undefined,
      span: 24,
      __slot__: {
        default: '主要按钮'
      },
      layout: 'colFormItem',
      type: 'primary',
      icon: 'ele-Search',
      round: false,
      size: 'medium',
      plain: false,
      circle: false,
      disabled: false,
      document: 'https://element.eleme.cn/#/zh-CN/component/button'
}]

export const commonComponents = [...inputComponents, ...selectComponents, ...layoutComponents]
  .map( t => Object.assign( { cmpType: 'common' }, t ) )

const getConfigByTag = ( targetList, tag ) => targetList.find( t => t.tag === tag )
const copyConfigAsCustom = ( rowConf, childrenConf ) => {
  const clone = ( target, conf = {} ) => {
    const template = JSON.parse( JSON.stringify( target ) )
    return Object.assign( {}, template, { cmpType: 'custom' }, conf )
  }
  const defaultRow = clone( layoutComponents[0], rowConf )
  defaultRow.children = childrenConf.map( t => clone( t.target, t.config ) )
  return defaultRow
}
// 定制组件添加cmpType = custom
export const customMadeComponents = [
  copyConfigAsCustom( { label: '请假组件', explain: null }, [
    {
      target: getConfigByTag( selectComponents, 'el-select-wrap' ),
      config: {
        label: "请假类型",
        required: true,
        options: [
          {
            label: "病假",
            value: "病假"
          },
          {
            label: "事假",
            value: "事假"
          },
          {
            label: "婚假",
            value: "婚假"
          },
          {
            label: "丧假",
            value: "丧假"
          },
          {
            label: "产假",
            value: "产假"
          },
          {
            label: "年假",
            value: "年假"
          }
        ],
      }
    },
    {
      target: getConfigByTag( selectComponents, 'fc-date-duration' ),
      config: {
        required: true,
        label: "日期范围",
        showDuration: true,
      }
    }
  ] ),
  copyConfigAsCustom( { label: "出差组件", explain: null }, [
    {
      target: getConfigByTag( inputComponents, 'el-input' ),
      config: {
        label: "出差事由",
        required: true
      }
    },
    {
      target: getConfigByTag( selectComponents, 'el-select-wrap' ),
      config: {
        label: "交通工具",
        required: true,
        options: [
          {
            label: "火车",
            value: "火车"
          },
          {
            label: "飞机",
            value: "飞机"
          },
          {
            label: "汽车",
            value: "汽车"
          },
          {
            label: "其他",
            value: "其他"
          }
        ]
      }
    },
    {
      target: getConfigByTag( selectComponents, 'el-select-wrap' ),
      config: {
        label: "单程往返",
        required: true,
        options: [
          {
            label: "单程",
            value: "单程"
          },
          {
            label: "往返",
            value: "往返"
          }
        ]
      }
    },
    {
      target: getConfigByTag( inputComponents, 'el-input' ),
      config: {
        label: "出发城市",
        required: true
      }
    },
    {
      target: getConfigByTag( inputComponents, 'el-input' ),
      config: {
        label: "目的城市",
        required: true
      }
    },
    {
      target: getConfigByTag( selectComponents, 'fc-date-duration' ),
      config: {
        label: "日期范围",
        showLabel: true,
  tag: "fc-date-duration",
        showDuration: true,
        required: true
      }
    },
    {
      target: getConfigByTag( inputComponents, 'el-input' ),
      config: {
        label: "出差备注",
        required: false
      }
    },
    {
      target: getConfigByTag( inputComponents, 'el-input' ),
      config: {
        label: "同行人",
        required: false
      }
    }
  ] )]
// .map( t => Object.assign( { cmpType: 'custom', t } ) )
// 组件rule的触发方式，无触发方式的组件不生成rule
// inputTable组件也有一份此常量的copy 如有改动 最好同步
export const trigger = {
  'el-input': 'blur',
  'el-input-number': 'blur',
  'el-select-wrap': 'change',
  'el-radio-group-wrap': 'change',
  'el-checkbox-group-wrap': 'change',
  'el-cascader': 'change',
  'el-time-picker': 'change',
  'el-date-picker': 'change',
  'el-rate': 'change',
  'fc-amount': 'change',
  'fc-time-duration': 'change',
  'fc-date-duration': 'change',
  'ai-ou-select': 'input'
}